package org.mybatis.logic;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class BusinessLogicOld<T> {
	/**
	 * scope: application
	 */
	protected SqlSessionFactory sqlMapper = null;
	protected String resource = "org/mybatis/config/configuration.xml";
	private Reader reader = null;
	protected SqlSession session = null;
	protected T mapper = null;
	
	public BusinessLogicOld(){
		try {
			reader = Resources.getResourceAsReader(resource);
			sqlMapper = new SqlSessionFactoryBuilder().build(reader);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}	
	
	public void openSession(){
		try {
			System.out.println(":AAAA");
			session = sqlMapper.openSession();
			System.out.println(":A");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void setMapper(Class<T> c){
		mapper =  session.getMapper(c);
	}
	public void commitSession(){
		session.commit();
	}
	
	public void closeSession(){
		session.close();
	}
}
